package org.genntii.warehousesystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.genntii.warehousesystem.domain.entity.Goods;

import java.math.BigDecimal;
import java.util.List;


@Mapper
public interface GoodsMapper extends BaseMapper<Goods> {

    @Update("update goods set status = 1 where id = #{id}")
    void enable(@Param("id") int id);

    @Update("update goods set status = 0 where id = #{id}")
    void unable(@Param("id")int id);

    @Update("update goods set on_sale = 1 where id = #{id}")
    void onSale(@Param("id")int id);

    @Update("update goods set on_sale = 0 where id = #{id}")
    void unSale(@Param("id")int id);

    @Update("update goods set name = #{name}," +
            "brand = #{brand}," +
            "description = #{description}," +
            "out_price = #{outPrice}," +
            "wholesale_price = #{wholesalePrice}," +
            "wholesale_num = #{wholesaleNum}," +
            "specification = #{specification}," +
            "bar_code = #{barCode} where id = #{id}")
    void update(@Param("name")String name,
                @Param("brand")int brand,
                @Param("description")String description,
                @Param("outPrice")BigDecimal outPrice,
                @Param("wholeSalePrice")BigDecimal wholeSalePrice,
                @Param("wholesaleNum")int wholesaleNum,
                @Param("specification")String specification,
                @Param("barCode")Long barCode,
                @Param("id")int id);

    @Select("select * from goods limit #{page},10")
    List<Goods> findByPage(@Param("page")int page);

    @Select("select *from goods where name like concat('%',#{word},'%') limit #{page},10")
    List<Goods> searchPage(@Param("word")String word, @Param("page")int page);

    @Update("update goods set img_src = #{src} where id = #{id}")
    void setSrc(@Param("src")String src, @Param("id")int id);

}
